package fr.castorflex.CshopFlex.Listeners;

import android.util.Log;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import fr.castorflex.CshopFlex.MainActivity;
import fr.castorflex.CshopFlex.Model.Item;

public class MyListViewListener implements OnItemClickListener,
		OnScrollListener {

	ListView list;
	MainActivity activity;

	public MyListViewListener(MainActivity a, ListView l) {
		activity = a;
		list = l;
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Log.i("clickList", "flex");
		Item i = (Item) list.getItemAtPosition(arg2);
		activity.displaySpecificItem(i);
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		if (totalItemCount == 0)
			return;
		boolean loadMore = (firstVisibleItem + visibleItemCount == totalItemCount);
		if (loadMore) {
			activity.launchThreadLoadMoreProducts();
		}

	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		// TODO Auto-generated method stub

	}


}
